<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/commonPage/common.jsp"%>
<html>
<head>
    <link rel="stylesheet" href="${base }/style/certificate.css">
    <link rel="stylesheet" href="${base }/style/certificate.css" media="print" />
    <script type="text/JavaScript" src="${base }/jquery/jQuery.print.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Title</title>

    <style media="print" type="text/css">
        .noprint {
            display:none
        }
        .print {
            margin-left:25%
        }
        @page {
                  size:  auto;   /* auto is the initial value */
                  margin: 0mm;  /* this affects the margin in the printer settings */
              }
    </style>
</head>
<body >
<p align="center">
    <input type="button" value="打印" onclick="doPrint()"/>
    <input type="button" value="关闭" onclick="closeWindow()"/>
</p>
<!--startprint-->
<div class='big-div' style=" position: relative;z-index: 99;" >
    <div class='bg-div'>
        <img src='${base}/images/certificate.png' style='height: 633px;width: 1030px;' />
        <div class='username' style="position: absolute;top: 325px;left: 300px;font-size: 25px;"></div>
        <div class='position' style=" position: absolute;top: 325px;left: 640px;font-size: 25px;"></div>
        <div class='date' style="position: absolute;top: 440px;left: 820px;font-size: 25px;"></div>
        <div class='uid' style=" position: absolute;top: 540px;left: 840px;font-size: 25px;"></div>
    </div>
</div>
<!--endprint-->
</body>
</html>
<script>
    getUinfo()
    function doPrint() {
        bdhtml=window.document.body.innerHTML;
        sprnstr="<!--startprint-->";
        eprnstr="<!--endprint-->";
        prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
        prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML=prnhtml;


        window.print();
        window.location.reload()
    }

    function getUinfo(){
        console.log(GetQueryString('uid'))
        $.ajax({
            url: "${base}/MembersController/getMembersList",
            type: "POST",
            data: {
                "keyWord": GetQueryString('uid')
            },
            dataType: "json",
            success: function (data) {
                var res=data[0]
                console.log(res)
                $(".username").text(res.username)
                $(".position").text(res.position)
                $(".date").text(getDate(res.joinTime))
                $(".uid").text(res.uid)
            }
        })

    }

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
        if (r != null) return unescape(r[2]);
        return null;
    }

    function closeWindow(){
        window.close();
    }
    function myprint()
    {
        $("#big-div").print()
    }
    function getDate(date){
        var formate=new Date(date)
        return formate.getFullYear()+"年"+formate.getMonth()+"月"+formate.getDay()+"日"
    }

</script>
